package com.nstar.base.container
{
	import mx.containers.Panel;
	import mx.controls.LinkButton;
	import flash.events.MouseEvent;
	import mx.effects.Resize;
	import flash.display.DisplayObject;
	import mx.effects.WipeDown;
	import mx.events.FlexEvent;
	import flash.events.Event;
	
	/**
	 * 可收缩的Panel
	 * 
	 * @author 李嘉陵
	 * @date 2007.1
	 */
	public class ResizePanel extends Panel
	{
		private var btResize:LinkButton;
		private var originHeight;
		
		private var expand:Resize = new Resize();
		private var contract:Resize = new Resize();
		
		public var wipeShow:Boolean = true;
		private var wipeIn:WipeDown = new WipeDown();
		
		public function ResizePanel() {
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,initButton);
			this.horizontalScrollPolicy = "off";
			this.verticalScrollPolicy = "off";
		}
		
		private function initButton(event:Event):void {
			btResize = new LinkButton();
			btResize.label = "-";
			btResize.addEventListener(MouseEvent.CLICK,resize);
			//btResize.right = 0;

			this.parent.addChild(btResize);
			btResize.setStyle("right",0);
			
			contract.heightTo = 40;
			
			contract.target = this;
			
			expand.target = this;

			
			
		}
		
		private function resize(event:Event):void {
				trace(this.height)
				if(originHeight == null ) {
					originHeight = this.parent.height;
					expand.heightTo = originHeight;
				}
				if(this.height == originHeight) {
					contract.end(); 
					contract.play();
					btResize.label = "+";
				}
				else {
					expand.end(); 
					expand.play();
					btResize.label = "-";
				}
				
		}
		
		private function initWipeIn():void {
			wipeIn.target = this;
			wipeIn.duration = 500;
			this.addEventListener(FlexEvent.CREATION_COMPLETE,showWipeIn);
			
			function showWipeIn():void {
				wipeIn.play();
			}
		}
		
	}
}